﻿
var monTothuLoyolaArray = new Array("07:45","08:00","08:15","08:45","09:00","09:15","09:45","10:00","10:15","10:45","11:00","11:20","11:40","12:00","12:20","12:40","13:00","13:20","13:40","14:00","14:20","14:40","15:00","15:20","15:40","16:00","16:20","16:40","17:00","17:20","17:40","18:00","18:30","18:45","19:30","20:00","20:30","20:50","21:20","21:40","22:10","22:30","23:00");
var fridayLoyolaArray = new Array("07:45","08:15","08:45","09:15","09:30","10:05","10:15","10:30","11:00","11:15","11:30","12:00","12:15","12:30","13:00","13:15","13:30","14:00","14:25","14:45","15:15","15:30","16:00","16:15","16:45","17:00","17:15","17:45","18:15","18:45","19:15");
var monTothuSGWArray = new Array("07:45", "08:15", "08:30", "08:45", "09:15", "09:30", "09:45", "10:15", "10:30", "10:40", "11:05", "11:20", "11:40", "12:00", "12:20", "12:40", "13:00", "13:20", "13:40", "14:00", "14:20", "14:40", "15:00", "15:20", "15:40", "16:00", "16:20", "16:40", "17:00", "17:20", "17:40", "18:00", "18:15", "19:00", "19:35", "20:05", "20:25", "20:55", "21:15", "21:45", "22:05", "22:35", "23:00");
var fridaySGWArray = new Array("07:45","08:15","08:45","09:15","09:40","09:55","10:30","10:45","11:00","11:30","11:45","12:00","12:30","12:45","13:00","13:30","13:45","14:00","14:25","14:55","15:10","15:45","15:55","16:30","16:45","17:15","17:30","17:45","18:15","18:45","19:15");

function checkNextBus() {
    var d = new Date();
    var currenttime = d.getHours() + ":" + d.getMinutes();
    var currentDate = d.getDay();
    var timeSGW = document.getElementById('TimeSGW');
    var timeLoy = document.getElementById('TimeLayola');
    
    if (currentDate == 0 || currentDate == 6) { // If it is either Saturday or Sunday, display no buses.
        timeSGW.innerHTML = "No buses";
        timeLoy.innerHTML = "No buses";
    } // End of week-end search
    else if(currentDate == 5){ // If its is Friday, then search the friday array.

        for (var i = 0; i < fridaySGWArray.length; i++) {
            if (fridaySGWArray[i] >= currenttime) {
                timeSGW.innerHTML = fridaySGWArray[i];
                break;
            }
        }

        for (var i = 0; i < fridayLoyolaArray.length; i++) {
            if (fridayLoyolaArray[i] >= currenttime) {
                timeLoy.innerHTML = fridayLoyolaArray[i];
                break;
            }
        }

    } // End of friday search
    else{ // If it is from Monday to Thursday, then search the corresponding array

        for (var i = 0; i < monTothuSGWArray.length; i++) {
            if (monTothuSGWArray[i] >= currenttime) {
                timeSGW.innerHTML = monTothuSGWArray[i];
                break;
            }
        }

        for (var i = 0; i < monTothuLoyolaArray.length; i++) {
            if (monTothuLoyolaArray[i] >= currenttime) {
                timeLoy.innerHTML = monTothuLoyolaArray[i];
                break;
            }
        }
    } // End of week days search

        
}


function onSchOver() {
    var box = document.getElementById('fullSch');
    var title = document.getElementById('fullSchText');
    box.style.transition = "all 0.5s ease";
    box.style.boxShadow = "0 0 30px rgba(255,255,255, 0.9)";
    title.style.textShadow = "10px 10px 0px rgba(10,10,10,0.1)";
}

function onSchOut() {
    var box = document.getElementById('fullSch');
    var title = document.getElementById('fullSchText');
    box.style.transition = "all 0.5s ease";
    box.style.boxShadow = "0 0 10px rgba(255,255,255, 0.9)";
    title.style.transition = "all 0.5s ease";
    title.style.textShadow = "4px 4px 0px rgba(0,0,0,0.1)";
}

function showSchMF() {
    var div = document.getElementById('scheduleMFHidden');
    var sch = document.getElementById('fullSchText');
    var scWE = document.getElementById('scheduleWEHidden');

    for (var i = 0; i < fridaySGWArray.length; i++) {
        scWE.innerHTML += "<input type=\"checkbox\">" + fridaySGWArray[i] + "</input><br/>";
    }

    if (div.className == "hidden") {
        div.className = "show";
        sch.innerHTML = "Show Map";
        sch.style.left = "3.2em";
    }
    else {
        div.className = "hidden";
        sch.innerHTML = "View Schedule";
        sch.style.left = "2.3em";
    }
}

function showSchWE() {
    var div = document.getElementById('scheduleWEHidden');
    var sch = document.getElementById('fullSchText');
    var scWE = document.getElementById('scheduleWEHidden');

    scWE.innerHTML += "<br/><br/><br/>";

    MSApp.execUnsafeLocalFunction(function() {
        for (var i = 0; i < fridaySGWArray.length; i++) {
            scWE.innerHTML += "<input type='checkbox'>"+fridaySGWArray[i]+"</input><br/>";
        }
    });

    if (div.className == "hidden") {
        div.className = "show";
        sch.innerHTML = "Show Map";
        sch.style.left = "3.2em";
    }
    else {
        div.className = "hidden";
        sch.innerHTML = "View Schedule";
        sch.style.left = "2.3em";
    }
}

function currentDate() {
    var d=new Date();
    var sch = document.getElementById('fullSchText');

    if (d.getDay() == 0 || d.getDay() == 6) {
        
    }
    else if (d.getDay() == 5) {
        showSchWE();
    }
    else {
        showSchMF();
    }
}